<template>
  <div class="root">
    <div class="advItem">
      <van-overlay :show="show">
        <div class="wrapper" @click.stop>
          <!-- <img src="http://qnkf.laigl.com/mobilepng/adv.png" alt=""> -->
          <img src="http://qnkf.laigl.com/20210420/solutionlogo.png" alt="" />
          <i class="iconfont icon-guanbi" @click="show = false"></i>
        </div>
      </van-overlay>
    </div>
    <div class="container">
      <div :class="showShadow ? 'head_box_on' : 'head_box'">
        <div class="adv">
          <i class="iconfont icon-bangzhu" @click="showAdv"></i>
        </div>
        <div class="title">我的学员</div>
        <div class="search">
          <i class="iconfont icon-sousuo" @click="search"></i>
          <input
            type="text"
            placeholder="搜索成员"
            @change="search"
            @input="showVal"
            @focus="onfocus"
            @blur="onblur"
            placeholder-style="color:#C5C9D5"
            v-model="searchVal"
          />
        </div>
        <div class="add_button" @click="goAdd">
          <i class="iconfont icon-tianjiayonghu"></i>添加学员
        </div>
      </div>
      <!-- 学院为空时显示 -->
      <div class="empty" v-if="user_list == ''">
        <img src="http://qnkf.laigl.com/mobilepng/empty1.png" alt="" />
        <img src="http://qnkf.laigl.com/mobilepng/empty2.png" alt="" />
        <div class="text">
          <p>还未有学员信息</p>
          <p>请先添加学员</p>
        </div>
      </div>
      <div class="content-box">
        <!-- <div class="user_list" v-for="(item,idx) in user_list" data-idx="idx" :key="idx">
						<div class="user_item">
							<div class="avatar">
								<img v-if="item.sex==1" :src="item.head_img==''?nantou:item.head_img" alt="">
								<img v-if="item.sex==0" :src="item.head_img==''?nvtou:item.head_img">
							</div>
							<div class="item_middle">
								<div class="username overtext">{{item.name}}</div> 
								<span class="gender">
									<img v-if="item.sex==1" style="width=1.3rem;height:1.3rem;margin-left:.5rem;" src="http://qnkf.laigl.com/mobilepng/nan.png" alt="">
									<img v-if="item.sex==0" style="width=1.3rem;height:1.3rem;margin-left:.5rem;" src="http://qnkf.laigl.com/mobilepng/nv.png" alt="">
								</span><br>
								<div class="info">
									<span class="age">{{item.birthday}}岁 </span><span class="phone"> {{item.phone}}</span>
								</div>
								<div class="file" @click="gorecovery(item.id)">
									<img src="http://qnkf.laigl.com/mobilepng/file.png" alt="" style="width: .7rem; height: .8rem;margin-right:0.5rem;"><span>康复档案</span>
								</div>
							</div>
							<div class="item_right" @click="goAssessment(item.id)"><i  class="iconfont icon-icon-test"></i>评估</div>
						</div>
					</div> -->

        <van-swipe-cell
          v-for="(item, idx) in user_list"
          data-idx="idx"
          :key="idx"
		  
        >
          <!-- <van-cell :border="false" title="单元格" value="内容" /> -->
          <div class="user_list">
            <div class="user_item">
              <div class="avatar">
                <img
                  v-if="item.sex == 0"
                  :src="item.head_img == '' ? nantou : item.head_img"
                  alt=""
                />
                <img
                  v-if="item.sex == 1"
                  :src="item.head_img == '' ? nvtou : item.head_img"
                />
              </div>
              <div class="item_middle">
                <div class="username overtext">{{ item.name }}</div>
                <span class="gender">
                  <img
                    v-if="item.sex == 0"
                    style="width=1.3rem;height:1.3rem;margin-left:.5rem;"
                    src="http://qnkf.laigl.com/mobilepng/nan.png"
                    alt=""
                  />
                  <img
                    v-if="item.sex == 1"
                    style="width=1.3rem;height:1.3rem;margin-left:.5rem;"
                    src="http://qnkf.laigl.com/mobilepng/nv.png"
                    alt=""
                  /> </span
                ><br />
                <div class="info">
                  <span class="age">{{ item.birthday }}岁 </span
                  ><span class="phone"> {{ item.phone }}</span>
                </div>
                <div class="file" @click="gorecovery(item.id)">
                  <img
                    src="http://qnkf.laigl.com/mobilepng/file.png"
                    alt=""
                    style="width: 0.7rem; height: 0.8rem; margin-right: 0.5rem"
                  /><span>康复档案</span>
                </div>
              </div>
              <div class="item_right" @click="goAssessment(item.id)">
                <i class="iconfont icon-icon-test"></i>评估
              </div>
            </div>
          </div>

          <template #right>
            <van-button square type="primary" @click="handleEdit(item.id)" text="编辑" />
            <van-button square type="danger" @click="handleDelete(item.id)" text="删除" />
          </template>
        </van-swipe-cell>
      </div>
    </div>
    <footer-comp v-show="ishide"></footer-comp>
  </div>
</template>

<script>
import { Notify, Toast } from "vant";
export default {
  data() {
    return {
      searchVal: "",
      nantou: "http://qnkf.laigl.com/mobilepng/nantou.png",
      nvtou: "http://qnkf.laigl.com/mobilepng/nvtou.png",
      show: false,
      user_list: [],
      userinfo: [],
      ishide: true,
      showShadow: false,
    };
  },
  created() {
    // 显示广告页
    let times = sessionStorage.getItem("open");
    if (!times) {
      this.showAdv();
    }
    this.getUserList();
    this.getuserinfo();
  },
  mounted() {
    window.addEventListener("scroll", this.roll);
  },
  methods: {
	  handleEdit(id){
		  this.$router.push({
			  path:"/adduser",
			  query:{
				  id,
				  edit:1,
			  }
		  })
	  },
	  handleDelete(id){
		  let openid = localStorage.getItem("openid");
		   this.$axios.post("solution/delete", { openid: openid ,id}).then((res) => {
				if(res.data.code==2000){
					Toast({
						message:res.data.msg
					})
					this.getUserList();
    				this.getuserinfo();
				}else{
					Toast({
						message:res.data.msg
					})
				}
				
			});
	  },
    roll() {
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      if (scrollTop > 0) {
        this.showShadow = true;
      } else {
        this.showShadow = false;
      }
    },
    // 获取学员信息
    getUserList() {
      let openid = localStorage.getItem("openid");
      this.$axios.post("solution/index", { openid: openid }).then((res) => {
        this.user_list = res.data.data;
      });
    },
    onfocus() {
      this.ishide = false;
    },
    // 输入框获取焦点时隐藏tabbar
    onblur() {
      this.ishide = true;
    },
    // 获取用户信息
    getuserinfo() {
      let openid = localStorage.getItem("openid");
      this.$axios.post("/user/index", { openid }).then((res) => {
        if (res.data.code == 2000) {
						this.userinfo = res.data.data.user_info;
					} else {
						Notify({ type: 'danger', message: res.data.msg });
					}
      });
    },
    // 格式化搜索内容
    showVal() {
      this.searchVal = this.searchVal.trim();
    },
    // 搜索学员
    search() {
      let openid = localStorage.getItem("openid");
      this.$axios
        .post("solution/index", {
          search: this.searchVal,
          openid,
        })
        .then((res) => {
          if (res.data.code == 2000) {
            if (res.data.data == "") {
              Notify({ type: "primary", message: "找不到该学员" });
              return;
            }
            Notify({ type: "success", message: "为您找到以下学员" });
            this.user_list = res.data.data;
          } else {
            Notify({ type: "warning", message: res.data.msg });
          }
        });
    },
    goAdd() {
      this.$router.push({
        path: "/adduser?user_id=" + this.userinfo[0].id,
      });
    },
    showAdv() {
      this.show = true;
      sessionStorage.setItem("open", "1");
    },
    // 前往评估第一步
    goAssessment(id) {
      this.$router.push({
		path: "/category?user_id=" + id,
	  });
	  
    },
    gorecovery(id) {
      this.$router.push({
        path: "/recovery?niledinut_id=" + id,
      });
    },
  },
};
</script>

<style scoped lang="less">
.root {
  overflow: hidden;
  margin-bottom: 3rem;
  width: 100%;
  height: 100%;
  .advItem {
    .van-overlay {
      z-index: 9999;
      .wrapper {
        width: 85%;
        height: 70% !important;
        position: absolute;
        top: 3rem;
        left: 2rem;
        img {
          width: 100%;
          // height: 100%;
          position: absolute;
          left: 0rem;
          bottom: 0rem;
          border-radius: 0.3rem;
          object-fit: cover;
        }
        i {
          color: #fff;
          font-size: 2rem;
          position: absolute;
          bottom: -3rem;
          left: 46%;
        }
      }
    }
  }
  .adv {
    position: fixed;
    top: -2.5rem;
    right: -2.5rem;
    width: 5rem;
    height: 5rem;
    transform: rotate(135deg);
    background: linear-gradient(135deg, #1fcad2, #15b3ce, #0384c4);
    overflow: hidden;
    i {
      position: absolute;
      bottom: 1.5rem;
      left: 3.4rem;
      font-size: 2rem;
      color: #fff;
      transform: rotate(-135deg);
    }
  }
  .container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding-bottom: 6rem;
    .head_box,
    .head_box_on {
      width: 100vw;
      box-sizing: border-box;
      height: 8.5rem;
      position: fixed;
      top: -2px;
      left: 0;
      background: #fff;
      z-index: 999;
    }
    .head_box_on {
      box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.05);
    }
    .empty {
      width: 27rem;
      height: 23rem;
      position: relative;
      img:nth-child(1) {
        width: 18rem;
        height: 14rem;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      }
      img:nth-child(2) {
        width: 7rem;
        height: 20rem;
        position: absolute;
        left: 65%;
      }
      .text {
        position: absolute;
        bottom: 1rem;
        left: 35%;
        font-size: 1.2rem;
        line-height: 1.8rem;
        text-align: center;
        color: #c6c8d5;
        letter-spacing: 0.1rem;
      }
    }
    .title {
      width: 100%;
      height: 1rem;
      text-align: left;
      font-size: 1.3rem;
      font-weight: 700;
      padding-left: 1rem;
      margin: 1.5rem 0 1.5rem 1rem;
    }
    .search {
      margin-left: 2rem;
      width: 55vw;
      height: 2.3rem;
      border: 0.15rem solid #c7cbd7;
      border-radius: 5rem;
      // padding: 0 0 .3rem .3rem;
      padding-bottom: 0.5rem;
      margin-bottom: 1.5rem;
      position: sticky;
      top: 0;
      i,
      input {
        display: inline-block;
        vertical-align: top;
      }
      i {
        font-size: 1.8rem;
        color: #c5c9d5;
        margin-top: 0.5rem;
        margin-left: 1rem;
        margin-right: 0.5rem;
      }
      input {
        margin-top: 0.3rem;
        width: 70%;
        height: 2.3rem;
        border: none;
        outline: none;
        font-size: 1.2rem;
      }
      input::-webkit-input-placeholder {
        color: #eaebef;
      }
    }
    .add_button,
    .search {
      display: inline-block;
    }
    .add_button {
      position: absolute;
      top: 4rem;
      right: 0rem;
      margin-right: 2rem;
      font-size: 1.2rem;
      margin-top: 0.8rem;
      i {
        font-size: 1.5rem;
        color: #000;
        font-weight: 700;
      }
    }
  }
  .content-box {
    width: 100vw;
    height: 90vh;
    // overflow: scroll;
    box-sizing: border-box;
    padding: 8.5rem 0 5rem 2rem;
    .user_list {
      .user_item {
        width: 100%;
        // margin-left: 2rem;
        border-bottom: 1px solid #ddd;
        margin-bottom: 0.5rem;
        position: relative;
        min-height: 6.5rem;
        .avatar {
          float: left;
          width: 5rem;
          margin-top: 0.5rem;
          height: 5rem;
          border-radius: 50%;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        .item_middle {
          width: 40vw;
          height: 6rem;
          padding-left: 1rem;
          float: left;
          .username,
          .gender {
            display: inline-block;
            vertical-align: bottom;
          }
          .gender {
            i {
              font-size: 1.3rem;
              font-weight: 600;
            }
          }
          .username {
            font-size: 1.3rem;
            font-weight: 600;
            width: 25vw;
          }
          .info {
            width: 100%;
            height: 1.5rem;
            font-size: 1.1rem;
            margin-top: 0.3rem;
            color: #c5c9d5;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
          .file {
            box-sizing: border-box;
            margin-top: 0.3rem;
            width: 6.5rem;
            padding: 0.1rem 0.5rem;
            border-radius: 1rem;
            color: #fff;
            height: 1.6rem;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient(to right, #1fcad2, #15b3ce, #0384c4);
            img,
            span {
              vertical-align: middle;
            }
          }
        }
        .item_right {
          position: absolute;
          right: 5vw;
          top: 2rem;
          width: 4.5rem;
          padding: 0 0.5rem;
          font-weight: 600;
          text-align: center;
          line-height: 2rem;
          border: 1px solid #000000;
          height: 2rem;
          border-radius: 3rem;
        }
      }
    }
  }
}
.van-button.van-button--primary.van-button--normal.van-button--square,
.van-button.van-button--danger.van-button--normal.van-button--square {
  height: 100%;
}
</style>
